/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;
import DAO.Iter.NhomDAO;
import TableModel.Nhom;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
 *
 * @author vt
 */
public class NhomDAOImpl extends HibernateDaoSupport implements NhomDAO {
    @Override
    public Long add(Nhom a) {
        Long result = (Long) this.getHibernateTemplate().save(a);
        return result;
    }

    @Override
    public void edit(Nhom a) {
        this.getHibernateTemplate().update(a);
    }

    @Override
    public void delete(Nhom a) {
       this.getHibernateTemplate().delete(a);
    }

    @Override
    public List<Nhom> findAll() {
        return  getHibernateTemplate().find("from Nhom nhom ");
    }

    @Override
    public List<Nhom> findByMaHP(String maHP) {
        return getHibernateTemplate().find("from Nhom nhom where nhom.mahp=?",maHP);
    }

    @Override
    public List<Nhom> findByNhom(int nhom) {
        return getHibernateTemplate().find("from Nhom nhom where nhom.nhom =?",nhom);
    }

    @Override
    public Long getMaNhom(String maHp, int nhom) {
        List<Nhom> list = getHibernateTemplate().find("from Nhom nhom where nhom.mahp =? and nhom.nhom =?",maHp,nhom);
        if(list.isEmpty()!= true){
            return list.get(0).getMaNhom();
        }
        else{
            return null;
        }
    }
    
}
